home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-09-16 | 21.5 KB | 521 lines | [TEXT/CCL2] |
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; item-defs.lisp
- ;;
- ;;
- ;; ©1989-1991 Apple Computer, Inc
- ;;
- ;; definitions of object functions for particular classes of dialog-items, to
- ;; support editing, printing, and copying.
- ;;
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; Change History
- ;;
- ;; 04/28/93 mwp Release
- ;; 11/02/92 bill Be more explicit about the parameters for the prototype
- ;; sequence dialog item.
- ;; ------------- 2.0
- ;; 03/05/92 wkf Changed "Print Item Source" button and "Print Dialog Source…"
- ;; menu item to make a Scratch Fred buffer.This is since one
- ;; rarely saves these buffers and this makes throwing them away
- ;; easier. One can always use "Save as" to keep them.
- ;; ------------- 2.0f3
- ;; 12/18/91 bill add package prefixes to commented out object-source-code
- ;; method for array-dialog-item
- ;; ------------- 2.0b4
- ;; 07/26/91 bill editors for fred-dialog-item's now have check box for
- ;; allow-tabs & draw-outline
- ;; 07/09/91 bill window-font -> view-font
- ;; 07/05/91 bill :srccopy -> :srcor
- ;; 04/24/91 bill ALMS's fix to (method object-source-code (dialog-item))
-
- (in-package :interface-tools)
-
- ;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; new classes
-
- (defclass dialog-item-editor (non-editable-dialog)
- ((edited-item :accessor dialog-item-editor-item)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; code for editing dialog-items
- ;;
-
- (defparameter *editor-items-start-pos* #@(180 20))
-
- (defun edit-dialog-item (item &optional (wpos #@(4 40)))
- (let ((my-ed (get-dialog-item-editor item)))
- (if my-ed
- (window-select my-ed)
- (setf (get-dialog-item-editor item)
- (make-instance 'dialog-item-editor
- :item item
- :view-position wpos)))))
-
- (defmethod initialize-instance ((editor dialog-item-editor) &rest initargs &key
- (item (make-instance 'button-dialog-item)))
- (declare (dynamic-extent initargs))
- (setf (dialog-item-editor-item editor) item)
- (apply #'call-next-method
- editor
- :view-size (dialog-item-editor-size item)
- :window-type :document
- :window-title (format nil "Editor for ~s" (dialog-item-text item))
- initargs)
- (add-editor-items item editor))
-
- (defmethod window-close :before ((editor dialog-item-editor))
- (setf (get-dialog-item-editor (dialog-item-editor-item editor)) nil))
-
- (defmethod dialog-item-editor-size ((item dialog-item))
- #@(344 253))
-
- (defmethod add-editor-items ((dialog-item dialog-item) editor)
- (let* ((enabled (dialog-item-enabled-p dialog-item))
- (text (dialog-item-text dialog-item)))
- (add-subviews
- editor
- (make-dialog-item 'static-text-dialog-item
- #@(4 4) #@(125 16) "Dialog-item-text:")
- (make-dialog-item 'editable-text-dialog-item
- #@(7 24) #@(148 80) text
- #'(lambda (item)
- (let ((text (dialog-item-text item)))
- (set-dialog-item-text dialog-item text)
- (set-window-title
- editor (format nil "Editor for ~s" text))))
- :allow-returns t)
- (make-dialog-item 'radio-button-dialog-item
- #@(5 115) #@(72 16) "Enabled"
- #'(lambda (item)
- (declare (ignore item))
- (dialog-item-enable dialog-item))
- :radio-button-pushed-p enabled)
- (make-dialog-item 'radio-button-dialog-item
- #@(85 115) #@(72 16) "Disabled"
- #'(lambda (item)
- (declare (ignore item))
- (dialog-item-disable dialog-item))
- :radio-button-pushed-p (not enabled))
- (make-dialog-item 'button-dialog-item
- #@(5 137) #@(125 16) "Set Item Action"
- #'(lambda (item)
- (declare (ignore item))
- (new-action-from-dialog dialog-item)))
- (make-dialog-item 'button-dialog-item
- #@(5 158) #@(125 16) "Set Item Font"
- #'(lambda (item)
- (declare (ignore item))
- (set-view-font
- dialog-item
- (choose-font-dialog (view-font dialog-item)))))
- (make-dialog-item 'button-dialog-item
- #@(5 179) #@(125 16) "Set Item Name"
- #'(lambda (item)
- (declare (ignore item))
- (set-item-nick-name dialog-item)))
- (make-dialog-item 'color-part-pop-up
- #@(4 201) #@(119 21) "Set Color" nil
- :part-codes '(:frame :text :body :thumb)
- :colored-object dialog-item)
- (make-dialog-item 'button-dialog-item
- #@(5 231) #@(125 16) "Print Item Source"
- #'(lambda (item)
- (declare (ignore item))
- (let* ((*print-length* nil)
- (*print-level* nil)
- (*print-array* t)
- (win (make-instance 'fred-window
- :scratch-p t)))
- (pprint (object-source-code dialog-item) win)
- (fred-update win)))))))
-
- ;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; definitions for various dialog-items
- ;;
-
- ;;;; *button* ;;;;;
-
- (add-editable-dialog-item (make-instance 'button-dialog-item
- :dialog-item-text "Button"))
-
- (defmethod add-editor-items ((button button-dialog-item) editor)
- (let* ((default (default-button-p button))
- (position *editor-items-start-pos*))
- (call-next-method)
- (add-subviews
- editor
- (make-dialog-item 'check-box-dialog-item
- position #@(116 16) "Default Button"
- #'(lambda (item)
- (let ((checked (check-box-checked-p item))
- (dialog (view-window button))
- (old-editor (get-dialog-item-editor button)))
- (setf (get-dialog-item-editor button) nil)
- (if checked
- (set-default-button dialog button)
- (set-default-button dialog nil))
- (setf (get-dialog-item-editor button) old-editor)))
- :check-box-checked-p default))))
-
-
- ;;;; *static-text* ;;;;;
-
- (add-editable-dialog-item (make-instance 'static-text-dialog-item
- :dialog-item-text "Static Text"))
-
- ;;;; *editable-text* ;;;;;
-
- (add-editable-dialog-item (make-instance 'editable-text-dialog-item
- :dialog-item-text "Edit Text"))
-
- (defmethod add-editor-items :after ((text-item fred-dialog-item) editor)
- (let* ((position *editor-items-start-pos*)
- (size #@(116 16))
- (delta (make-point 0 (+ (point-v size) 5))))
- (add-subviews
- editor
- (make-dialog-item 'check-box-dialog-item
- position size "Allow Returns"
- #'(lambda (item)
- (setf (allow-returns-p text-item)
- (check-box-checked-p item)))
- :check-box-checked-p (allow-returns-p text-item))
- (make-dialog-item 'check-box-dialog-item
- (setq position (add-points position delta))
- size "Allow Tabs"
- #'(lambda (item)
- (setf (allow-tabs-p text-item)
- (check-box-checked-p item)))
- :check-box-checked-p (allow-tabs-p text-item))
- (make-dialog-item 'check-box-dialog-item
- (setq position (add-points position delta))
- size "Draw outline"
- #'(lambda (item)
- (invalidate-view text-item t)
- (setf (slot-value text-item 'ccl::draw-outline)
- (check-box-checked-p item))
- (invalidate-view text-item))
- :check-box-checked-p
- (slot-value text-item 'ccl::draw-outline)))))
-
-
- ;;;; *check-box* ;;;;;
-
- (add-editable-dialog-item (make-instance 'check-box-dialog-item
- :dialog-item-text "Check Box"))
-
- (defmethod add-editor-items :after ((box-item check-box-dialog-item) editor)
- (let* ((checked (check-box-checked-p box-item))
- (position *editor-items-start-pos*))
- (add-subviews
- editor
- (make-dialog-item 'check-box-dialog-item
- position #@(155 16) "Check Box Checked"
- #'(lambda (item)
- (if (check-box-checked-p item)
- (check-box-check box-item)
- (check-box-uncheck box-item)))
- :check-box-checked-p checked))))
-
-
-
- ;;;; *radio-button* ;;;;;
-
- (add-editable-dialog-item (make-instance 'radio-button-dialog-item
- :dialog-item-text "Radio Button"))
-
- (defmethod add-editor-items :after ((radio radio-button-dialog-item) editor)
- (let* ((pushed (radio-button-pushed-p radio))
- (position *editor-items-start-pos*))
- (add-subviews
- editor
- (make-dialog-item 'check-box-dialog-item
- position #@(160 16) "Radio Button Pushed"
- #'(lambda (item)
- (if (check-box-checked-p item)
- (radio-button-push radio)
- (radio-button-unpush radio)))
- :check-box-checked-p pushed)
- (make-dialog-item 'button-dialog-item
- (add-points position #@(0 24)) #@(150 16) "Set Item Cluster"
- #'(lambda (item)
- (declare (ignore item))
- (setf (radio-button-cluster radio)
- (read-from-string
- (get-string-from-user
- "Please enter a new cluster for the radio button."
- :initial-string
- (format nil "~s" (radio-button-cluster radio))))))))))
-
- ;;;; *table* ;;;;;
-
- (defmethod add-editor-items :after ((table table-dialog-item) editor)
- (let ((h-scrollp (table-hscrollp table))
- (v-scrollp (table-vscrollp table))
- (position *editor-items-start-pos*))
- (labels ((change-scroll (check-box which-bar)
- (let* ((checked (check-box-checked-p check-box))
- (owning-dialog (view-window table))
- (old-editor (get-dialog-item-editor table)))
- (setf (get-dialog-item-editor table) nil)
- (set-view-container table nil)
- (ecase which-bar
- (:vertical
- (setf (table-vscrollp table) checked))
- (:horizontal
- (setf (table-hscrollp table) checked)))
- (set-view-container table owning-dialog)
- (setf (get-dialog-item-editor table) old-editor))))
- (add-subviews
- editor
- (make-dialog-item 'button-dialog-item
- position #@(130 16) "Set Cell Size"
- #'(lambda (item)
- (declare (ignore item))
- (set-cell-size
- table
- (read-from-string
- (get-string-from-user
- "Please enter a new Cell Size."
- :initial-string
- (format nil "~s" (ppoint (cell-size table))))))
- (invalidate-view table)))
- (make-dialog-item 'check-box-dialog-item
- (add-points position #@(0 22)) #@(175 16) "Horizontal Scrollbar"
- #'(lambda (item)
- (change-scroll item :horizontal))
- :check-box-checked-p h-scrollp)
- (make-dialog-item 'check-box-dialog-item
- (add-points position #@(0 44)) #@(175 16) "Vertical Scrollbar"
- #'(lambda (item)
- (change-scroll item :vertical))
- :check-box-checked-p v-scrollp)))))
-
- (defun get-new-table-data (old-data data-name)
- (let* ((*print-length* nil)
- (*print-level* nil))
- (read-from-string
- (get-text-from-user
- (format nil "Please enter a new ~a for the table." data-name)
- (format nil "~s" old-data)))))
-
- ;;sequence-dialog-item
-
-
- (add-editable-dialog-item (make-instance 'sequence-dialog-item
- :table-sequence '(1 2 3)
- :view-size #@(29 63)
- :table-hscrollp nil
- :table-vscrollp nil))
-
- (defmethod add-editor-items :after ((sequence sequence-dialog-item) editor)
- (let ((position (add-points *editor-items-start-pos* #@(0 66)))
- (orient (slot-value sequence 'ccl::sequence-order)))
- (add-subviews
- editor
- (make-dialog-item 'button-dialog-item
- position #@(130 16) "Set Table Sequence"
- #'(lambda (item)
- (declare (ignore item))
- (set-table-sequence
- sequence
- (get-new-table-data
- (table-sequence sequence) "sequence"))))
- (make-dialog-item 'button-dialog-item
- (add-points position #@(0 22)) #@(130 16) "Set Wrap Length"
- #'(lambda (item)
- (declare (ignore item))
- (setf (slot-value sequence 'ccl::sequence-wrap-length)
- (read-from-string
- (get-string-from-user
- "Please enter a new length."
- :initial-string
- (format nil "~a"
- (slot-value sequence 'ccl::sequence-wrap-length)))))
- (set-table-sequence
- sequence (table-sequence sequence))))
- (make-dialog-item 'static-text-dialog-item
- (add-points position #@(0 44)) #@(130 16) "Orientation:")
- (make-dialog-item 'radio-button-dialog-item
- (add-points position #@(30 60)) #@(100 16) "Vertical"
- #'(lambda (item)
- (declare (ignore item))
- (setf (slot-value sequence 'ccl::sequence-order) :vertical)
- (set-table-sequence
- sequence (table-sequence sequence)))
- :radio-button-pushed-p (eq orient :vertical))
- (make-dialog-item 'radio-button-dialog-item
- (add-points position #@(30 76)) #@(100 16) "Horizontal"
- #'(lambda (item)
- (declare (ignore item))
- (setf (slot-value sequence 'ccl::sequence-order) :horizontal)
- (set-table-sequence
- sequence (table-sequence sequence)))
- :radio-button-pushed-p (eq orient :horizontal)))))
- #|
- ;;array-dialog-item
-
- (add-editable-dialog-item (make-instance 'array-dialog-item))
-
- (defmethod add-editor-items :after ((array array-dialog-item) editor)
- (let ((position (add-points *editor-items-start-pos* #@(0 66))))
- (add-subviews
- editor
- (make-dialog-item 'button-dialog-item
- position #@(130 16) "Set Table Array"
- #'(lambda (item)
- (declare (ignore item))
- (let* ((*print-array* t))
- (set-table-array
- array
- (get-new-table-data (table-array array)
- "array"))))))))
- |#
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; definitions for printing the source code
- ;;
-
- (defmethod pprint-source ((window window))
- (let* ((*print-length* nil)
- (*print-level* nil)
- (*print-array* t)
- (win (make-instance 'fred-window :scratch-p t)))
- (pprint (object-source-code window) win)
- (fred-update win)))
-
- (defmethod object-source-code ((window window) &aux my-font)
- `(make-instance ',(if (window-color-p window) 'color-dialog 'dialog)
- :window-type ,(window-type window)
- ,@(let ((title (window-title window)))
- (if (or (string-equal title "Untitled Dialog")
- (string-equal title "Untitled"))
- nil
- `(:window-title ,title)))
- :view-position ,(let ((pos (window-centered-p window)))
- (if (fixnump pos)
- (ppoint pos)
- (list 'quote pos)))
- :view-size ,(ppoint (view-size window))
- ,@(if (rref (wptr window) windowRecord.goawayflag)
- nil
- '(:close-box-p nil))
- ,@(if (equal (setq my-font (view-font window))
- '("Chicago" 0 :srcor :plain))
- nil
- `(:view-font ',my-font))
- :view-subviews (list ,@(map 'list #'(lambda (item)
- (object-source-code item))
- (view-subviews window)))))
-
- (defmethod object-source-code ((item dialog-item) &aux my-font)
- `(make-dialog-item ',(class-name (class-of item))
- ,(ppoint (view-position item))
- ,(ppoint (view-size item))
- ,(dialog-item-text item)
- ,(let* ((f (dialog-item-action-function item))
- (code (and (functionp f) (uncompile-function f))))
- (cond ((symbolp f) `',f)
- (code `#',code)
- (t nil)))
- ,@(let ((nick-name (view-nick-name item)))
- (and nick-name
- `(:view-nick-name ',nick-name)))
- ,@(if (dialog-item-enabled-p item)
- ()
- '(:dialog-item-enabled-p nil))
- ,@(if (equal (setq my-font (view-font item))
- (view-font (view-window item)))
- ()
- `(:view-font ',my-font))
- ,@(let ((color-list (part-color-list item)))
- (and color-list
- `(:part-color-list ',color-list)))))
-
-
- ;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; definitions for various dialog-items
- ;;
-
- ;;;; *button* ;;;;;
-
- (defmethod object-source-code ((item button-dialog-item))
- (nconc (call-next-method)
- `(:default-button ,(default-button-p item))))
-
- ;;;; *static-text* ;;;;;
-
- ;no additional defs needed
-
-
- ;;;; *editable-text* ;;;;;
-
- (defmethod object-source-code ((item fred-dialog-item))
- (nconc (call-next-method)
- `(:allow-returns ,(allow-returns-p item))))
-
-
- ;;;; *check-box* ;;;;;
-
- (defmethod object-source-code ((item check-box-dialog-item))
- (nconc (call-next-method)
- (if (check-box-checked-p item)
- (list :check-box-checked-p t)
- ())))
-
-
- ;;;; *radio-button* ;;;;;
-
- (defmethod object-source-code ((item radio-button-dialog-item))
- (nconc (call-next-method)
- `(,@(if (radio-button-pushed-p item)
- '(:radio-button-pushed-p t)
- nil)
- ,@(let ((cluster (radio-button-cluster item)))
- (if (eql 0 (radio-button-cluster item))
- nil
- `(:radio-button-cluster ,cluster))))))
-
-
- ;;;; *table* ;;;;;
-
- (defmethod object-source-code ((item table-dialog-item))
- (nconc (call-next-method)
- `(:cell-size ,(ppoint (cell-size item))
- :selection-type ,(slot-value item 'ccl::selection-type)
- :table-hscrollp ,(table-hscrollp item)
- :table-vscrollp ,(table-vscrollp item))))
-
-
- ;;;; *sequence-table* ;;;;;
-
- (defmethod object-source-code ((item sequence-dialog-item))
- (let* ((wrap (slot-value item 'ccl::sequence-wrap-length))
- (order (slot-value item 'ccl::sequence-order)))
- (nconc (call-next-method)
- `(:table-sequence ',(table-sequence item))
- (if (eq wrap most-positive-fixnum)
- nil
- `(:sequence-wrap-length ,wrap))
- (if (eq order :vertical)
- nil
- `(:sequence-order ,order)))))
-
- #|
- ;;;; *array-table* ;;;;;
-
- (defmethod object-source-code ((item ccl:array-dialog-item))
- (nconc (call-next-method)
- `(:table-array ',(ccl:table-array item)))) |#
-
-
- ;;all done
- (provide 'item-defs)
-